package com.xiaochong.tir.manager.controller;

import com.github.pagehelper.PageInfo;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.service.common.config.oss.OSSTool;
import com.xiaochong.service.common.config.redis.RedisServer;
import com.xiaochong.tir.common.data.po.*;
import com.xiaochong.tir.common.data.vo.CurrencyTraVo;
import com.xiaochong.tir.common.util.RedisKeysUtils;
import com.xiaochong.tir.manager.component.RedisCacheComponent;
import com.xiaochong.service.common.config.redis.RedisServer;
import com.xiaochong.tir.manager.service.*;
import com.xiaochong.tir.manager.util.ManagerVersion;
import com.xiaochong.tir.manager.util.ReturnResult;
import com.xiaochong.tir.manager.util.SessionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

/**
 * Created by admin on 2018/4/26.
 */
@Controller
@Api(value = "货币维护")
@RequestMapping(value = ManagerVersion.API_V1_PREFIX+"currency/")
public class CurrencyManagerController {

    @Autowired
    private CurrencyInfoService currencyInfoService;
    @Autowired
    private CurrencyConceptCategoryService currencyConceptCategoryService;
    @Autowired
    private CurrencyIndustryMiddleService currencyIndustryMiddleService;
    @Autowired
    private RedisCacheComponent redisCacheComponent;
    @Autowired
    private RedisServer redisServer;
    @Autowired
    private BasePeriodHistoryService basePeriodHistoryService;
    @Autowired
    private CoinSummarizeService coinSummarizeService;
    @Autowired
    private OSSTool ossTool;
    @Autowired
    private ExchangeTransactionpairMiddleService exchangeTransactionpairMiddleService;
    /**
     * 货币上下架
     * @param id
     * @param enableFlag
     * @return
     */

    @ApiOperation(value = "货币上下架",notes = "货币上下架")
    @PostMapping(value = "enableCurrency")
    @ResponseBody
    public int enableCurrency(@RequestParam("id") Integer id,@RequestParam("enable_flag") Boolean enableFlag){
        redisServer.set(RedisKeysUtils.LOGINNAME,"货币上下架");
        CurrencyInfo cinfo = new CurrencyInfo();
        if(null != enableFlag&&enableFlag.equals(true) ){
            cinfo.setEnableFlag(false);
        }else {
            cinfo.setEnableFlag(true);
        }
        cinfo.setId(id);
        cinfo.setUpdateTime(new Date());
        int count = currencyInfoService.updateByPrimaryKey(cinfo,currencyInfoService.selectByPrimaryKey(id));
        redisCacheComponent.init();
        return count;
    }

    /**
     * 删除货币
     * @param id
     * @return
     */
    @ApiOperation(value = "删除货币",notes = "删除货币")
    @PostMapping("delCurrency")
    @ResponseBody
    public Object delCurrency(@RequestParam("id") Integer id){
        redisServer.set(RedisKeysUtils.LOGINNAME,"删除货币");
        //删除货币表记录
        CurrencyInfo currencyInfo=new CurrencyInfo();
        CurrencyInfo old = currencyInfoService.selectByPrimaryKey(id);
        currencyInfo.setId(id);
        currencyInfo.setDeleteFlag(true);
        currencyInfo.setEnableFlag(false);
        currencyInfoService.updateByPrimaryKey(currencyInfo,old);
        //删除货币概念中间表记录
        currencyConceptCategoryService.deleteBatch(new CurrencyConceptCategory().setCurrencyId(id));
        //删除货币行业中间表记录
        currencyIndustryMiddleService.deleteBatch(new CurrencyIndustryMiddle().setCurrencyId(id));
        redisCacheComponent.init();
        return new ReturnResult<CurrencyConceptCategory>(0, " 删除成功！", 1, 0);
    }

    /**
     * 币种管理页面
     * @return
     */
    @RequestMapping(value = "currencymanage",method = RequestMethod.GET)
    public String currencyManagePage(){
        return "currencymanage/currencyList";
    }

    
    /**   
     * @Title: eidtCurrency   
     * @Description: TODO(修改页面)   
     * @param: @param id
     * @param: @param model
     * @param: @param map
     * @param: @return      
     * @return: String      
     * @throws   
     */ 
    @RequestMapping(value = "eidtCurrency",method = RequestMethod.GET)
    public String eidtCurrency(@RequestParam("id") Integer id, Model model,Map<String,Object> map){
    	CurrencyInfo currencyInfo = currencyInfoService.selectByPrimaryKey(id);
    	List<CurrencyIndustryCategory> industlist = currencyInfoService.industryList();
        List<ConceptCategory> conceptlist = currencyInfoService.conceptCategoryList();
        if(null!=industlist){
            for(CurrencyIndustryCategory cu:industlist){
                for(CurrencyIndustryMiddle cm:currencyInfo.getCurrencyIndustryList()){
                    if(cu.getId().equals(cm.getIndustryCategoryId())){
                        cu.setIsCheck(1);
                    }
                }
            }
        }
        if(null!=conceptlist){
            for(ConceptCategory cc:conceptlist){
                for(CurrencyConceptCategory ccc:currencyInfo.getCurrencyConceptList()){
                    if(cc.getId().equals(ccc.getConceptCategory())){
                        cc.setIsCheck(1);
                    }
                }
            }
        }
        if(null!=currencyInfo){
            if(StringUtils.isNotBlank(currencyInfo.getImageUrl())&&!currencyInfo.getImageUrl().contains("http")){
                currencyInfo.setImageKey(currencyInfo.getImageUrl());
                currencyInfo.setImageUrl(ossTool.getOSSUrl(currencyInfo.getImageKey()));
            }
        }
        model.addAttribute("data",currencyInfo);
        map.put("industList",industlist);
        map.put("conceptList",conceptlist);
        return "currencymanage/currencyEdit";
    }
    
    /**   
     * @Title: listCurrency   
     * @Description: TODO(列表)   
     * @param: @param coin_name_cn
     * @param: @param currency_diagnosis_flag
     * @param: @param enable_flag
     * @param: @param page
     * @param: @param limit
     * @param: @return      
     * @return: Object      
     * @throws   
     */
    @ApiOperation(value = "查询货币列表",notes = "查询货币列表")
    @PostMapping(value = "listCurrency")
    @ResponseBody
    public Object listCurrency(CurrencyInfo currencyInfo,
            @RequestParam("page")Integer page,
            @RequestParam("limit")Integer limit){
    	PageInfo<CurrencyInfo> curList = currencyInfoService.listCurrency(currencyInfo,page,limit);
    	if(null!=curList){
            for (int i = 0; i < curList.getList().size(); i++) {
                CurrencyInfo info = curList.getList().get(i);
                if(StringUtils.isNotBlank(info.getImageUrl())&&!info.getImageUrl().contains("http")){
                    info.setImageUrl(ossTool.getOSSUrl(info.getImageUrl()));
                }
            }
        }
    	return new ReturnResult<CurrencyInfo>(0,"成功",curList.getList(),curList.getTotal());
    }
    
    /**   
     * @Title: updateCurrency   
     * @Description: TODO(编辑)   
     * @param: @param session
     * @param: @param currencyInfo
     * @param: @param map
     * @param: @return      
     * @return: String      
     * @throws   
     */
    @ApiOperation(value = "编辑货币",notes = "编辑货币")
    @PostMapping(value = "/updateCurrency")
    public String updateCurrency(CurrencyInfo currencyInfo,Map<String, Object> map){
        redisServer.set(RedisKeysUtils.LOGINNAME,"编辑货币");
        try {
            if(StringUtils.isNotBlank(currencyInfo.getCmcId())){
                List<CurrencyInfo> cmcidlist = currencyInfoService.selectByEntityList(
                        new CurrencyInfo().setCmcId(currencyInfo.getCmcId()));
                if(null != cmcidlist && cmcidlist.size() > 1){
                    map.put("msg", "重复的cmcId");
                    return "currencymanage/currencyList";
                }
            }
        	currencyConceptCategoryService.deleteBycurrencyId(currencyInfo.getId());
        	currencyIndustryMiddleService.deleteBycurrencyId(currencyInfo.getId());
            BasePeriodHistory basePeriodHistory = new BasePeriodHistory();
            basePeriodHistory.setCurrencyInfoId(currencyInfo.getId());
            basePeriodHistory.setCreateTime(new Date());
            basePeriodHistory.setCoinSymbol(currencyInfo.getSymbol());
          if(null!=currencyInfo.getIndustryCategoryIds()&&!"".equals(currencyInfo.getIndustryCategoryIds())){
        	  CurrencyConceptCategory currencyConceptCategory = new CurrencyConceptCategory();
        	  currencyConceptCategory.setCurrencyId(currencyInfo.getId());
       		  String[] categoryIds = currencyInfo.getIndustryCategoryIds().split(",");
       		  for(int i=0;i<categoryIds.length;i++){
       			currencyConceptCategory.setConceptCategory(Integer.valueOf(categoryIds[i]));
                currencyConceptCategory.setCreateTime(new Date());
                currencyConceptCategory.setUpdateTime(new Date());
       			currencyConceptCategoryService.insertSelective(currencyConceptCategory);
       			//货币基期表记录
                  basePeriodHistory.setBasePeriodMark(4);
                  basePeriodHistory.setConceptIndustryCurrencyId(Integer.valueOf(categoryIds[i]));
                  basePeriodHistoryService.insertSelective(basePeriodHistory);
       			//概念基期状态缓存
       			redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_NOTION_BASE_PERIOD+categoryIds[i]),String.valueOf(1));
       			redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_NOTION_BASE_jiqi_PERIOD+categoryIds[i]),String.valueOf(1));
       		  }
       	  }
            if(null!=currencyInfo.getIndustryIndustryIds()&&!"".equals(currencyInfo.getIndustryIndustryIds())){
             CurrencyIndustryMiddle currencyIndustryMiddle = new CurrencyIndustryMiddle();
           	 currencyIndustryMiddle.setCurrencyId(currencyInfo.getId());
           	 String[] industryIds = currencyInfo.getIndustryIndustryIds().split(",");
           	 for(int i=0;i<industryIds.length;i++){
           		currencyIndustryMiddle.setIndustryCategoryId(Integer.valueOf(industryIds[i]));
           		currencyIndustryMiddle.setCreateTime(new Date());
           		currencyIndustryMiddle.setUpdateTime(new Date());
           		currencyIndustryMiddleService.insertSelective(currencyIndustryMiddle);
           		//行业基期状态缓存
           		redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_INDUSTRY_BASE_PERIOD+industryIds[i]),String.valueOf(1));
           		redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_INDUSTRY_BASE_jiqi_PERIOD+industryIds[i]),String.valueOf(1));
                 //存入货币基期表
                 basePeriodHistory.setConceptIndustryCurrencyId(Integer.valueOf(industryIds[i]));
                 basePeriodHistory.setBasePeriodMark(3);
                 basePeriodHistoryService.insertSelective(basePeriodHistory);
     		  }
       	  }
       	   currencyInfo.setUpdateTime(new Date());
           currencyInfoService.updateByPrimaryKey(currencyInfo,currencyInfoService.selectByPrimaryKey(currencyInfo.getId()));
           //权重基期状态缓存
           redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_WEIGHTS_BASE_PERIOD+currencyInfo.getId()),String.valueOf(1));
            //存入货币基期表
           basePeriodHistory.setBasePeriodMark(2);
           basePeriodHistory.setConceptIndustryCurrencyId(currencyInfo.getId());
           basePeriodHistoryService.insertSelective(basePeriodHistory);
           redisCacheComponent.init();
        } catch (Exception e) {
        	e.printStackTrace();
            map.put("msg", "修改失败");
            LogTrace.error(getClass().getSimpleName() + "/updateCurrency", e.getMessage(), e);
        }
        return "currencymanage/currencyList";
    }

    /**
     * 新增货币页面
     * @return
     */
    @GetMapping("addcur")
    public String createcurrencyPage(Model model){
        List<CurrencyIndustryCategory> industlist = currencyInfoService.industryList();
        List<ConceptCategory> conceptlist = currencyInfoService.conceptCategoryList();
        model.addAttribute("industList",industlist);
        model.addAttribute("conceptList",conceptlist);
        return "currencymanage/addcurrency";
    }

    /**
     * 新增货币方法
     * @param currencyInfo
     * @param map
     * @return
     */
    @ApiOperation(value = "新增货币",notes = "新增货币")
    @PostMapping("inscurr")
    public Object insertCurrency(CurrencyInfo currencyInfo,Map<String, Object> map){
        redisServer.set(RedisKeysUtils.LOGINNAME,"新增货币");
        try {
            if(StringUtils.isNotBlank(currencyInfo.getCmcId())){
                List<CurrencyInfo> cmcidlist = currencyInfoService.selectByEntityList(
                        new CurrencyInfo().setCmcId(currencyInfo.getCmcId()));
                if(null != cmcidlist &&  cmcidlist.size() > 0){
                    map.put("msg", "重复的cmcId");
                    return "currencymanage/currencyList";
                }
            }
            CurrencyInfo info = currencyInfoService.selectByEntity(currencyInfo);
            if(null != info){
                map.put("msg", "重复添加");
                return "currencymanage/currencyList";
            }
            BasePeriodHistory basePeriodHistory = new BasePeriodHistory();
            currencyInfo.setCreateTime(new Date());
            currencyInfo.setUpdateTime(new Date());
            currencyInfoService.insertSelective(currencyInfo);//插入货币表，返回新增的id
            basePeriodHistory.setCreateTime(new Date());
            basePeriodHistory.setCurrencyInfoId(currencyInfo.getId());
            basePeriodHistory.setCoinSymbol(currencyInfo.getSymbol());
            //权重基期状态缓存
            redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_WEIGHTS_BASE_PERIOD+currencyInfo.getId()),String.valueOf(1));
            //存入货币基期表
            basePeriodHistory.setBasePeriodMark(2);
            basePeriodHistory.setConceptIndustryCurrencyId(currencyInfo.getId());
            basePeriodHistoryService.insertSelective(basePeriodHistory);
            redisCacheComponent.init();
            //行业表记录
            if(StringUtils.isNotBlank(currencyInfo.getIndustryCategoryIds())){
                CurrencyConceptCategory currencyConceptCategory = new CurrencyConceptCategory();
                currencyConceptCategory.setCurrencyId(currencyInfo.getId());
                String[] categoryIds = currencyInfo.getIndustryCategoryIds().split(",");
                for(int i=0;i<categoryIds.length;i++){
                    currencyConceptCategory.setConceptCategory(Integer.valueOf(categoryIds[i]));
                    currencyConceptCategory.setCreateTime(new Date());
                    currencyConceptCategory.setUpdateTime(new Date());
                    currencyConceptCategoryService.insertSelective(currencyConceptCategory);
                    //货币基期表记录
                    basePeriodHistory.setConceptIndustryCurrencyId(Integer.valueOf(categoryIds[i]));
                    basePeriodHistory.setBasePeriodMark(4);
                    basePeriodHistoryService.insertSelective(basePeriodHistory);
                    //概念基期状态缓存
                    redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_NOTION_BASE_PERIOD+categoryIds[i]),String.valueOf(1));
                    redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_NOTION_BASE_jiqi_PERIOD+categoryIds[i]),String.valueOf(1));
                }
            }
            if(StringUtils.isNotBlank(currencyInfo.getIndustryIndustryIds())){
                CurrencyIndustryMiddle currencyIndustryMiddle = new CurrencyIndustryMiddle();
                currencyIndustryMiddle.setCurrencyId(currencyInfo.getId());
                String[] industryIds = currencyInfo.getIndustryIndustryIds().split(",");
                for(int i=0;i<industryIds.length;i++){
                    currencyIndustryMiddle.setIndustryCategoryId(Integer.valueOf(industryIds[i]));
                    currencyIndustryMiddle.setCreateTime(new Date());
                    currencyIndustryMiddle.setUpdateTime(new Date());
                    currencyIndustryMiddleService.insertSelective(currencyIndustryMiddle);
                    //行业基期状态缓存
                    redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_INDUSTRY_BASE_PERIOD+industryIds[i]),String.valueOf(1));
                    redisServer.set(String.valueOf(RedisKeysUtils.CURRCY_INDUSTRY_BASE_jiqi_PERIOD+industryIds[i]),String.valueOf(1));
                    //存入货币基期表
                    basePeriodHistory.setConceptIndustryCurrencyId(Integer.valueOf(industryIds[i]));
                    basePeriodHistory.setBasePeriodMark(3);
                    basePeriodHistoryService.insertSelective(basePeriodHistory);
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            map.put("msg", "添加失败");
            LogTrace.error(getClass().getSimpleName() + "/addcurrency", e.getMessage(), e);
        }
        return "currencymanage/currencyList";
    }

    /**
     * web货币所属的交易所、交易对列表
     * @param id
     * @param coinNameCn
     * @param model
     * @return
     */
    @GetMapping("webCurTra")
    public String currencyTra(@RequestParam("id")Integer id,
                              @RequestParam("coinNameCn")String coinNameCn,
                              @RequestParam("symbol")String symbol,
                              Model model){
        List<CurrencyTraVo> list = currencyInfoService.selectCurrencyTraList(id);
        model.addAttribute("currencyId",id);
        model.addAttribute("coinNameCn",coinNameCn);
        model.addAttribute("symbol",symbol);
        model.addAttribute("size",list.size());
        return "currencymanage/webCurTraPage";
    }

    /**
     * web查询与货币关联的交易对
     * @param currencyId
     * @return
     */
    @ApiOperation(value = "web查询与货币关联的交易对",notes = "web查询与货币关联的交易对")
    @PostMapping("listCurrencyTra")
    @ResponseBody
    public Object listCurrencyTra(@RequestParam("currencyId")Integer currencyId){
        List<CurrencyTraVo> list = currencyInfoService.selectCurrencyTraList(currencyId);
        return new ReturnResult<>(0,"成功",list,list.size());
    }

    /**
     * web删除货币与交易对的关联
     * @param currencyId
     * @return
     */
    @ApiOperation(value = "web删除货币与交易对的关联",notes = "web删除货币与交易对的关联")
    @PostMapping("delCurrencyTra")
    @ResponseBody
    public Object delCurrencyTra(@RequestParam("id")Integer currencyId){
        currencyInfoService.updateCurrencyTra(currencyId);
        return new ReturnResult<>(0,"成功",0,0);
    }

    /**
     * web查询没有关联且启用的所有交易对、交易所关联列表页面
     * @param id
     * @param coinNameCn
     * @param model
     * @return
     */
    @GetMapping("webExTra")
    public Object webExTra(@RequestParam("id")Integer id,
                           @RequestParam("coinNameCn")String coinNameCn,
                           @RequestParam("symbol")String symbol,
                           @RequestParam("size")String size
                            ,Model model){
        model.addAttribute("currencyId",id);
        model.addAttribute("coinNameCn",coinNameCn);
        model.addAttribute("symbol",symbol);
        model.addAttribute("size",size);
        return "currencymanage/webExTraPage";
    }

    /**
     * web查询没有关联且启用的所有交易对、交易所关联列表
     * @param cv
     * @param pageSize
     * @param pageIndex
     * @return
     */
    @ApiOperation(value = "web查询没有关联且启用的所有交易对、交易所关联列表",notes = "web查询没有关联且启用的所有交易对、交易所关联列表")
    @PostMapping("selExchangeTra")
    @ResponseBody
    public Object exchangeTraList(CurrencyTraVo cv,
                                  @RequestParam("limit")Integer pageSize,@RequestParam("page")Integer pageIndex){
        PageInfo<CurrencyTraVo> info = currencyInfoService.selExchangeTraList(cv,pageSize,pageIndex);
        return new ReturnResult<CurrencyTraVo>(0,"成功",info.getList(),info.getTotal());
    }

    /**
     * web关联交易对和货币(新增)
     * @param etmId
     * @param currencyId
     * @return
     */
    @ApiOperation(value = "web关联交易对和货币",notes = "web关联交易对和货币")
    @PostMapping("addCurrencyTra")
    @ResponseBody
    public Object addCurrencyTra(@RequestParam("etmId")Integer etmId,
                                 @RequestParam("currencyId")Integer currencyId){
        redisServer.set(RedisKeysUtils.LOGINNAME,"web关联交易对、货币");
        CurrencyInfo info =new CurrencyInfo();
        info.setId(currencyId);
        info.setExchangeTranMiddleId(etmId);
        info.setUpdateTime(new Date());
        CurrencyInfo old = currencyInfoService.selectByPrimaryKey(info.getId());
        currencyInfoService.editByPrimaryKey(info,old);
        return new ReturnResult<>(0,"成功",0,0);
    }


    /**
     * 货币编辑概括页面
     * @param id
     * @param model
     * @return
     */
    @GetMapping("addoreditlate")
    public Object addOrEdit(@RequestParam("id") Integer id, Model model){
        model.addAttribute("currencyInfoId",id);
        //查询编辑概括信息
        CoinSummarize coinSummarize =
                coinSummarizeService.selectByEntity(new CoinSummarize().setCurrencyInfoId(id));
        if(null == coinSummarize){
            return "coinsummarize/addencapsulates";
        }else {
            if(null != coinSummarize.getZeAffiliate()){
                for(CoinSummarizeAffiliated item:coinSummarize.getZeAffiliate()){
                    if(StringUtils.isNotBlank(item.getAffiliatedType())){
                        if("1".equals(item.getAffiliatedType())){
                            if(StringUtils.isNotBlank(item.getExt())){
                                coinSummarize.setPersonExt(item.getExt());
                            }
                        }else if("2".equals(item.getAffiliatedType())){
                            if(StringUtils.isNotBlank(item.getExt())){
                                coinSummarize.setCourseExt(item.getExt());
                            }
                        }
                    }
                }
            }
            model.addAttribute("summarize",coinSummarize);
            return "coinsummarize/eidtencapsulates";
        }
    }

    /**
     * web货币已关联交易对列表
     * @param id
     * @param coinNameCn
     * @param model
     * @return
     */
    @ApiOperation(value = "web货币已关联交易对列表",notes = "web货币已关联交易对列表")
    @GetMapping("appCurTra")
    public String appCurrencyTra(@RequestParam("id")Integer id,
                              @RequestParam("coinNameCn")String coinNameCn,
                              @RequestParam("symbol")String symbol,
                              Model model){
        model.addAttribute("currencyId",id);
        model.addAttribute("coinNameCn",coinNameCn);
        model.addAttribute("symbol",symbol);
        return "currencymanage/appCurTraPage";
    }

    /**
     * 查询app端与货币关联的交易对列表
     * @return
     */
    @ApiOperation(value = "查询app端与货币关联的交易对列表",notes = "查询app端与货币关联的交易对列表")
    @PostMapping("selCurTra")
    @ResponseBody
    public Object selCurTraList(@RequestParam("currencyId")Integer id){
        List<CurrencyTraVo> list = currencyInfoService.selCurTraList(id);
        return new ReturnResult<CurrencyTraVo>(0,"成功",list,list.size());
    }

    /**
     *app查询没有关联且启用的所有交易对、交易所关联列表页面
     * @param id
     * @param coinNameCn
     * @param model
     * @return
     */
    @GetMapping("appExTra")
    public Object exchangeTraPage(@RequestParam("id")Integer id,
                                  @RequestParam("coinNameCn")String coinNameCn,
                                  @RequestParam("symbol")String symbol,
                                  Model model){
        model.addAttribute("currencyId",id);
        model.addAttribute("coinNameCn",coinNameCn);
        model.addAttribute("symbol",symbol);
        return "currencymanage/appExTraPage";
    }

    /**
     * app查询与没有货币关联且启用的交易对
     * @param cv
     * @param pageSize
     * @param pageIndex
     * @return
     */
    @ApiOperation(value = "app查询与没有货币关联且启用的交易对",notes = "app查询与没有货币关联且启用的交易对")
    @PostMapping("selAppExTra")
    @ResponseBody
    public Object selAppExTra(CurrencyTraVo cv,
                              @RequestParam("limit")Integer pageSize,
                              @RequestParam("page")Integer pageIndex){
        PageInfo<CurrencyTraVo> info = currencyInfoService.selAppExTra(cv,pageSize,pageIndex);
        return new ReturnResult<CurrencyTraVo>(0,"成功",info.getList(),info.getTotal());
    }

    /**
     *app关联交易对、货币
     * @param etmId
     * @param currencyId
     * @param exId
     * @return
     */
    @ApiOperation(value = "app关联交易对、货币",notes = "app关联交易对、货币")
    @PostMapping("addAppCurTra")
    @ResponseBody
    public Object addAppCurTra(@RequestParam("etmId")String etmId,
                               @RequestParam("currencyId") Integer currencyId,
                               @RequestParam("exId")String exId){
        redisServer.set(RedisKeysUtils.LOGINNAME,"app关联交易对、货币");
        List<CurrencyTraVo> list = currencyInfoService.selCurTraList(currencyId);
        String [] etmIdarr = etmId.split(",");
        String [] exIdarr = exId.split(",");
        ExchangeTransactionpairMiddle middle = null;
        if(list.size()+etmIdarr.length > 10){
            return new ReturnResult<>(-1,"已经关联"+list.size()+"个交易对，最多还能关联" + (10-list.size()) + "个",1,1);
        }
        for (int i = 0; i < etmIdarr.length ; i++) {
            middle = new ExchangeTransactionpairMiddle();
            if(StringUtils.isNotBlank(etmIdarr[i])&&StringUtils.isNotBlank(exIdarr[i])){
                middle.setId(Integer.valueOf(etmIdarr[i]));
                ExchangeTransactionpairMiddle old =
                        exchangeTransactionpairMiddleService.selectByPrimaryKey(middle.getId());
                middle.setExchangeId(Integer.valueOf(exIdarr[i]));
                middle.setCurrencyId(currencyId);
                middle.setUpdateTime(new Date());
                middle.setEnableFlag(old.getEnableFlag());
                middle.setQuantifyCurrencySelect(old.getQuantifyCurrencySelect());
                middle.setSelected(old.getSelected());
                exchangeTransactionpairMiddleService.updateByPrimaryKey(middle,old);
            }
        }
        return new ReturnResult<>(0,"成功",1,1);
    }

    /**
     * app删除交易对、货币关联
     * @param id
     * @return
     */
    @ApiOperation(value = "app删除交易对、货币关联",notes = "app删除交易对、货币关联")
    @PostMapping("delAppCurTra")
    @ResponseBody
    public Object delAppCurTra(@RequestParam("id")Integer id){
        redisServer.set(RedisKeysUtils.LOGINNAME,"app删除交易对、货币关联");
        exchangeTransactionpairMiddleService.updateByEtmId(id);
        return new ReturnResult<>(0,"成功",1,1);
    }

}
